/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package View.ClusterizationPanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JTable;

/**
 *
 * @author Snowangelic
 */
public class CentroidTable extends JTable implements MouseListener{
    ClusterizationWindow main;
    public CentroidTable(){}
    public void setParent(ClusterizationWindow main){
        this.setModel(new CentroidTableModel(main));
        this.main=main;
        getColumn("No").setMaxWidth(20);
        getColumn("Color").setPreferredWidth(20);
        setDefaultRenderer(Color.class, new ColorRenderer(true));
        addMouseListener(this);
        this.setSize(640,100);
        this.setOpaque(true);
        this.setVisible(true);
        Dimension maxSize=new Dimension(640,(getRowCount()*20));
        this.setMaximumSize(maxSize);
        repaint();
    }

    void updateCentroidSelelction(){
       boolean[] centroidSelected=new boolean[getRowCount()];
       for(int i=0;i<getRowCount();i++){
           if(isRowSelected(i)) centroidSelected[i]=true;
           else centroidSelected[i]=false;
       }
       main.updateCentroidSelection(centroidSelected);
    }

    public int getDesiredHeight(){
        /*
        if(getRowCount()==0) return 0;
        else if (getRowCount()<=7) return ((getRowCount()+1)*this.getRowHeight()+5);
        else return 160;
         * */
        return 300;
    }

    public void mouseClicked(MouseEvent e) {
    }

    public void mousePressed(MouseEvent e) {
    }

    public void mouseReleased(MouseEvent e) {
        updateCentroidSelelction();
    }

    public void mouseEntered(MouseEvent e) {
    }

    public void mouseExited(MouseEvent e) {
    }
}
